#!/usr/bin/php
<?php
	if(!(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))) {
		die('Must be run from the command line\n');
	}
	$argc = $_SERVER["argc"];
	$argv = $_SERVER["argv"];
	function out($s=''){
		echo $s;
		echo "\n";
		flush();
	}
	function help(){
		out("Splinter - Teal app compiler\n\n./splinter.php (<flag>|<input folder>) [<outputta3>]\n	-h	display help message\n	-a	create a Teal app (*.ta3)\n	-d	create a Teal driver (*.td3)\n	-v	show version information");
	}
	if($argc == 1){
		out('Must have at least one arguement');
		help();
		die();
	}elseif($argc == 2 && ($argv[1] != '-h' && $argv[1] != '-v' )){
		out('Arguement errors');
		help();
		die();
	}
	switch($argv[1]){
		case '-h':
			help();
		break;
		case '-v':
			out('Splinter version 0.0.1');
		break;
		default:
			if(!isset($argv[2]))
				$argv[] = 'app';
			exec('zip '.$argv[2].' '.$argv[1].'/* ');
		break;
	}
	die();
?>
